home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 November / CPNL0711.ISO / boekhoud / finan / BADGER finance v1.0 beta 2.exe / xampplite / phpMyAdmin / libraries / url_generating.lib.php < prev    next >
PHP Script  |  2006-05-12  |  6KB  |  207 lines

  1. <?php
  2. /* $Id: url_generating.lib.php,v 2.10.2.1 2006/05/12 15:26:16 nijel Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5.  
  6. /**
  7.  * URL/hidden inputs generating.
  8.  */
  9.  
  10.  
  11. /**
  12.  * Generates text with hidden inputs.
  13.  *
  14.  * @see     PMA_generate_common_url()
  15.  * @param   string   optional database name
  16.  * @param   string   optional table name
  17.  * @param   int      indenting level
  18.  *
  19.  * @return  string   string with input fields
  20.  *
  21.  * @global  string   the current language
  22.  * @global  string   the current conversion charset
  23.  * @global  string   the current connection collation
  24.  * @global  string   the current server
  25.  * @global  array    the configuration array
  26.  * @global  boolean  whether recoding is allowed or not
  27.  *
  28.  * @access  public
  29.  *
  30.  * @author  nijel
  31.  */
  32. function PMA_generate_common_hidden_inputs($db = '', $table = '', $indent = 0, $skip = array())
  33. {
  34.     if (is_array($db)) {
  35.         $params  =& $db;
  36.         $_indent = empty($table) ? $indent : $table;
  37.         $_skip   = empty($indent) ? $skip : $indent;
  38.         $indent  =& $_indent;
  39.         $skip    =& $_skip;
  40.     } else {
  41.         $params = array();
  42.         if (isset($db) && strlen($db)) {
  43.             $params['db'] = $db;
  44.         }
  45.         if (isset($table) && strlen($table)) {
  46.             $params['table'] = $table;
  47.         }
  48.     }
  49.  
  50.     if (! empty($GLOBALS['server'])
  51.     &&  $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
  52.         $params['server'] = $GLOBALS['server'];
  53.     }
  54.     if (empty($_COOKIE['pma_lang'])
  55.     && ! empty($GLOBALS['lang'])) {
  56.         $params['lang'] = $GLOBALS['lang'];
  57.     }
  58.     if (empty($_COOKIE['pma_charset'])
  59.     && ! empty($GLOBALS['convcharset'])) {
  60.         $params['convcharset'] = $GLOBALS['convcharset'];
  61.     }
  62.     if (empty($_COOKIE['pma_collation_connection'])
  63.     && ! empty($GLOBALS['collation_connection'])) {
  64.         $params['collation_connection'] = $GLOBALS['collation_connection'];
  65.     }
  66.  
  67.     $params['token'] = $_SESSION['PMA_token'];
  68.  
  69.     if (! is_array($skip)) {
  70.         if (isset($params[$skip])) {
  71.             unset($params[$skip]);
  72.         }
  73.     } else {
  74.         foreach ($skip as $skipping) {
  75.             if (isset($params[$skipping])) {
  76.                 unset($params[$skipping]);
  77.             }
  78.         }
  79.     }
  80.  
  81.     $spaces = str_repeat('    ', $indent);
  82.  
  83.     $return = '';
  84.     foreach ($params as $key => $val) {
  85.         $return .= $spaces . '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($val) . '" />' . "\n";
  86.     }
  87.  
  88.     return $return;
  89. }
  90.  
  91. /**
  92.  * Generates text with URL parameters.
  93.  *
  94.  * <code>
  95.  * // note the ?
  96.  * echo 'script.php?' . PMA_generate_common_url('mysql', 'rights');
  97.  * // produces with cookies enabled:
  98.  * // script.php?db=mysql&table=rights
  99.  * // with cookies disabled:
  100.  * // script.php?server=1&lang=en-utf-8&db=mysql&table=rights
  101.  *
  102.  * $params['myparam'] = 'myvalue';
  103.  * $params['db']      = 'mysql';
  104.  * $params['table']   = 'rights';
  105.  * // note the missing ?
  106.  * echo 'script.php' . PMA_generate_common_url($params);
  107.  * // produces with cookies enabled:
  108.  * // script.php?myparam=myvalue&db=mysql&table=rights
  109.  * // with cookies disabled:
  110.  * // script.php?server=1&lang=en-utf-8&myparam=myvalue&db=mysql&table=rights
  111.  *
  112.  * // note the missing ?
  113.  * echo 'script.php' . PMA_generate_common_url();
  114.  * // produces with cookies enabled:
  115.  * // script.php
  116.  * // with cookies disabled:
  117.  * // script.php?server=1&lang=en-utf-8
  118.  * </code>
  119.  *
  120.  * @param   mixed    assoc. array with url params or optional string with database name
  121.  *                   if first param is an array there is also an ? prefixed to the url
  122.  * @param   string   optional table name only if first param is array
  123.  * @param   string   character to use instead of '&' for deviding
  124.  *                   multiple URL parameters from each other
  125.  *
  126.  * @return  string   string with URL parameters
  127.  *
  128.  * @global  string   the current language
  129.  * @global  string   the current conversion charset
  130.  * @global  string   the current connection collation
  131.  * @global  string   the current server
  132.  * @global  array    the configuration array
  133.  * @global  boolean  whether recoding is allowed or not
  134.  *
  135.  * @access  public
  136.  *
  137.  * @author  nijel
  138.  */
  139. function PMA_generate_common_url ($db = '', $table = '', $delim = '&')
  140. {
  141.     if (is_array($db)) {
  142.         $params =& $db;
  143.         $delim  = empty($table) ? $delim : $table;
  144.         $questionmark = '?';
  145.     } else {
  146.         $params = array();
  147.         if (isset($db) && strlen($db)) {
  148.             $params['db'] = $db;
  149.         }
  150.         if (isset($table) && strlen($table)) {
  151.             $params['table'] = $table;
  152.         }
  153.         $questionmark = '';
  154.     }
  155.  
  156.     // use seperators defined by php, but prefer ';'
  157.     // as recommended by W3C
  158.     $php_arg_separator_input = ini_get('arg_separator.input');
  159.     if (strpos($php_arg_separator_input, ';') !== false) {
  160.         $separator = ';';
  161.     } elseif (strlen($php_arg_separator_input) > 0) {
  162.         $separator = $php_arg_separator_input{0};
  163.     } else {
  164.         $separator = '&';
  165.     }
  166.  
  167.     // check wether to htmlentity the separator or not
  168.     if ($delim === '&') {
  169.         $delim = htmlentities($separator);
  170.     } else {
  171.         $delim = $separator;
  172.     }
  173.  
  174.     if (isset($GLOBALS['server'])
  175.       && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
  176.         $params['server'] = $GLOBALS['server'];
  177.     }
  178.  
  179.     if (empty($_COOKIE['pma_lang'])
  180.       && ! empty($GLOBALS['lang'])) {
  181.         $params['lang'] = $GLOBALS['lang'];
  182.     }
  183.     if (empty($_COOKIE['pma_charset'])
  184.       && ! empty($GLOBALS['convcharset'])) {
  185.         $params['convcharset'] = $GLOBALS['convcharset'];
  186.     }
  187.     if (empty($_COOKIE['pma_collation_connection'])
  188.       && ! empty($GLOBALS['collation_connection'])) {
  189.         $params['collation_connection'] = $GLOBALS['collation_connection'];
  190.     }
  191.  
  192.     $params['token'] = $_SESSION['PMA_token'];
  193.  
  194.     $param_strings = array();
  195.     foreach ($params as $key => $val) {
  196.         $param_strings[] = urlencode($key) . '=' . urlencode($val);
  197.     }
  198.  
  199.     if (empty($param_strings)) {
  200.         return '';
  201.     }
  202.  
  203.     return $questionmark . implode($delim, $param_strings);
  204. }
  205.  
  206. ?>
  207.